package com.zwb.aiwebsite.controller;

import com.zwb.aiwebsite.common.ResponseResult;
import com.zwb.aiwebsite.dto.SolutionDTO;
import com.zwb.aiwebsite.entity.solution.TbSolution;
import com.zwb.aiwebsite.entity.solution.TbSolutionType;
import com.zwb.aiwebsite.service.TbSolutionService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * 解决方案控制器
 * @author 2825075112@qq.com
 */
@Controller
@AllArgsConstructor
public class SolutionController {

    private final TbSolutionService tbSolutionService;
    
    @GetMapping("/admin/solution/{page}")
    public String index(@PathVariable String page){
        return "/admin/solution/" + page;
    }

    @PostMapping("/solution/type")
    @ResponseBody
    public ResponseResult<Void> addsolutionType(@RequestBody TbSolutionType tbsolutionType){
        tbSolutionService.addSolutionType(tbsolutionType);
        return ResponseResult.ok();
    }

    @GetMapping("/solution/type/all")
    @ResponseBody
    public ResponseResult<List<TbSolutionType>> getAllsolutionType(){
        List<TbSolutionType> all = tbSolutionService.getAllSolutionType();
        return ResponseResult.okOf(all);
    }

    @DeleteMapping("/solution/type/{id}")
    @ResponseBody
    public ResponseResult<Void> delsolutionType(@PathVariable Integer id){
        tbSolutionService.delSolutionType(id);
        return ResponseResult.ok();
    }

    @GetMapping("/solution/all")
    @ResponseBody
    public ResponseResult<List<TbSolution>> getAllsolution(){
        List<TbSolution> all = tbSolutionService.getAllSolution();
        return ResponseResult.okOf(all);
    }

    @DeleteMapping("/solution/{id}")
    @ResponseBody
    public ResponseResult<Void> delsolution(@PathVariable Integer id){
        tbSolutionService.delSolution(id);
        return ResponseResult.ok();
    }

    @PostMapping("/solution")
    @ResponseBody
    public ResponseResult<Void> addsolution(@RequestBody SolutionDTO solutionDTO){
        tbSolutionService.addSolution(solutionDTO);
        return ResponseResult.ok();
    }

    @GetMapping("/solution/info/all")
    @ResponseBody
    public ResponseResult<List<SolutionDTO>> getAllsolutionInfo(){
        List<SolutionDTO> all = tbSolutionService.getAllSolutionInfo();
        return ResponseResult.okOf(all);
    }
}
